<template>
  <div class="loading">
    <div class="DetailsLogManagement">
      <div class="tableBox">
        <el-table v-loading="loading" :data="tableData" style="width: 100%">
          <el-table-column label="序号" width="120">
            <template slot-scope="scope">{{(scope.$index + 1) + ((page - 1) * size)}}</template>
          </el-table-column>
          <el-table-column prop="Name" label="用户名" min-width="180"></el-table-column>
          <el-table-column prop="Operate" label="操作" width="180"></el-table-column>
          <el-table-column prop="Content" label="操作内容" width="180"></el-table-column>
          <el-table-column prop="IP" label="登录地址" width="180"></el-table-column>
          <el-table-column sortable prop="Time" label="登录时间" width="180"></el-table-column>
          <el-table-column sortable prop="OutTime" label="登出时间" width="180"></el-table-column>
        </el-table>
        <!--分页-->
        <div class="page">
          <el-pagination
            background
            @size-change="sizeChange"
            @current-change="currentChange"
            :current-page="page"
            :page-size="size"
            :page-sizes="sizes"
            :layout="layout"
            :total="sumSize"
          ></el-pagination>
        </div>
        <div class="registerView">
          <div class="userInfo">
            <div slot="footer" class="dialog-footer" align="center">
              <el-button type="primary" @click="handleRegister()">注 册</el-button>
              <el-button @click="cancel()">取 消</el-button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import * as sysTool from '../../../js/systemTool'
import * as cookie from '../../../js/cookie'
export default {
  name: 'DetailsLogManagement',
  data () {
    return {
      loading: true,
      requestCatch: false,
      tableData: [], // 表格数据
      sizes: [10, 20, 50],
      layout: 'total, sizes, prev, pager, next, jumper',
      page: 1, // 按翻页
      size: 10, // 每页几条
      sumSize: 0,
      ip: '1.1.1.1',
      area: '北京市',
      brower: 'chrome',
      os: 'windows7'
    }
  },

  methods: {
    // 初始化获取数据
    init () {
      this.loading = true
      this.requestCatch = false
      this.getTableList()
    },
    // 展示所有信息
    getTableList () {
      var brower = sysTool.GetCurrentBrowser()
      var os = sysTool.GetOs()
      var username = cookie.getCookie('userAccountNumber')
      var password = cookie.getCookie('userAccountPassword')
      var data = {
        Method: 'GetDetialLog',
        Name: username,
        Password: password,
        Device_ID: os,
        Platform: brower,
        Page: this.page,
        PageSize: this.size
      }
      var msg = JSON.stringify(data)
      var data2 = new FormData()
      data2.append('content', msg)
      let url = '/api/systemlog/systemlog.php'
      this.axios.post(url, data2).then((res) => {
        console.log('res', res)
        var mycars = res.data.Data
        this.sumSize = res.data.TotalNumber
        let num = 1
        if (mycars != null) {
          for (const item of mycars) {
            item.num = num++
          }
          this.tableData = mycars
          console.log('tableData', this.tableData)
        }
        setTimeout(() => {
          this.loading = false
          this.requestCatch = false
        }, 1.5 * 1000)
      })
    },

    // 每页显示条数修改
    sizeChange (size) {
      this.size = size
      this.getTableList()
    },
    // 切换分页
    currentChange (page) {
      this.page = page
      this.getTableList()
    }
  },
  mounted () {
    this.init()
  }
}
</script>
<style scoped>
.ManagementPage {
  width: 100%;
  min-height: 100%;
  background: #ffffff;
  padding: 20px;
  box-sizing: border-box;
}
</style>
